package vn.igolf.gui;

import java.awt.Color;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;

public class ScreenMapGUI extends MapGUI implements MouseMotionListener, MouseListener{
	  private volatile int screenX = 0;
	  private volatile int screenY = 0;
	  private volatile int myX = 0;
	  private volatile int myY = 0;
	  
    //Adjustments to put Duke's toe at the cursor's tip.
//  private static final int XFUDGE = 40;
//  private static final int YFUDGE = 57;
    private static final int XFUDGE = 10;
    private static final int YFUDGE = 5;

	public JLabel mapLabel;
    public JLabel dukeLabel;
    public DraggableComponent mark;
    
    public ScreenMapGUI () {

    	mark = new DraggableComponent();
        final ImageIcon map = createImageIcon("images/map1x.png");
        mapLabel = new JLabel(map);
        if (map != null) {
            mapLabel.setBounds(0, 0,
            		map.getIconWidth(),
            		map.getIconHeight());
        } else {
            System.err.println("Map icon not found; using black square instead.");
            mapLabel.setBounds(0, 0, 1013, 636);
            mapLabel.setOpaque(true);
            mapLabel.setBackground(Color.BLACK);
        }
        //Create and load the duke icon.
        final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif");

        //Create and add the Duke label to the layered pane.
        dukeLabel = new JLabel(icon);
        if (icon != null) {
            dukeLabel.setBounds(0, 0,
                                icon.getIconWidth(),
                                icon.getIconHeight());
        } else {
            System.err.println("Duke icon not found; using black square instead.");
            dukeLabel.setBounds(0, 0, 30, 30);
            dukeLabel.setOpaque(true);
            dukeLabel.setBackground(Color.BLACK);
        }

    }

    
    // MouseListener
    @Override
    public void mouseClicked(MouseEvent e) { }

    @Override
    public void mousePressed(MouseEvent e) {
      screenX = e.getXOnScreen();
      screenY = e.getYOnScreen();

      myX = getX();
      myY = getY();
    }

    @Override
    public void mouseReleased(MouseEvent e) { }

    @Override
    public void mouseEntered(MouseEvent e) { }

    @Override
    public void mouseExited(MouseEvent e) { }


    // MouseMotionListener
    @Override
    public void mouseDragged(MouseEvent e) {
      int deltaX = e.getXOnScreen() - screenX;
      int deltaY = e.getYOnScreen() - screenY;

      mark.setLocation(myX + deltaX, myY + deltaY);
    }

    @Override
    public void mouseMoved(MouseEvent e) { }
    
}
